﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.Model;
using rock.UI.common;
using rock.DAL;
using rock.common;

namespace rock.UI.custom
{
    public partial class FormShowCustomRentRoom : Form
    {
        private int CURRENT_PAGE = 1;
        DalHOUSE_ROOM dalHOUSE_ROOM = new DalHOUSE_ROOM();
        public  ModelRENT_CUSTOM _ModelRENT_CUSTOM { get; set; }
        public FormShowCustomRentRoom()
        {
            InitializeComponent();
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
            ViewUtils.setDataGridViewStlye(this.dataGridView1);
        }

        private void FormShowCustomRentRoom_Load(object sender, EventArgs e)
        {
            refreshData(1);
        }


        //刷新数据
        public void refreshData(int goPage)
        {


            CURRENT_PAGE = goPage;
         

            StringBuilder where = new StringBuilder(
                 "( 1=1 )"
                );


            where.Append(" AND RENT_CUSTOM.SEQID =  " + _ModelRENT_CUSTOM.SEQID);

            PageDataSet ds = dalHOUSE_ROOM.GetListByPage(where.ToString(), " SEQID DESC ", CURRENT_PAGE, 999);
            this.dataGridView1.DataSource = ds.DataSet.Tables[0];
             


        }

        

        public void setStatusWithDataGrid(DataGridView dgv)
        {
            for (int a = 0; a < dgv.Rows.Count; a++)
            {

                try
                {

                    int status = (int)dgv.Rows[a].Cells["STATUS_INT"].Value;

                    DataGridViewTextBoxCell dgvcc = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["STATUS_STR"];
                    dgvcc.Value = Constant.getByRoomStatus(status).Name;
                }
                catch (Exception)
                {

                }
            }
        }

        private void dataGridView1_RowPostPaint_1(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            setStatusWithDataGrid(this.dataGridView1);
        }
    }
}
